<?	
	/* Se asegura que el archivo es incluido por el index */
	defined( 'LOAD_MODULE_ACTION' ) or die( 'No esta permitido el acceso directo a ' . __FILE__ );  
		$this->oTmpObject = new Menu_componente_frm( $this );
	
	class Menu_componente_frm extends Frm
	{
	function setValue ( $ncMenu, $ncOrden )
		{
			$cSql = "SELECT  nOrden, ncComponente, nPanel, cParametros
				FROM gtMenuComponente
				WHERE ncMenu = '$ncMenu' AND  ncOrden = '$ncOrden' ";
			$aDatos = $this->oDatabase->getArray($cSql);	
			$this->setFieldsArray ( $aDatos );
			$this->aFields[ncMenuClave]->setValue( $ncMenu );	
			$this->armarParametros();
		}
	function armarParametros()
	{
		$ncComponente = $this->aFields['ncComponente']->getValue() ;
		if ( !$ncComponente )  return false;
		
		list( $cModule, $cAccion ) = $this->oDatabase->getArray("SELECT cModulo, cAccion FROM gtComponente WHERE ncComponente = $ncComponente");
		if ( $cModule &&  $cAccion  ) 
		{
			$aVariables = stringParametersToArray( $this->aFields[cParametros]->getValue()  );
			$oModule =& loadModule($cModule );
			$oModule->loadTemplatePage($cAccion);
			foreach($oModule->aDatos[$cAccion][aParametros] as  $aParametro)
			{
				$cListaParam .= $aParametro[0] . ',';
				if ( is_array($aParametro[2]) )
				{
					$this->aFields[$aParametro[0]]		= new InputList( $aParametro[1], $aParametro[0], $aVariables[$aParametro[0]] );
					$this->aFields[$aParametro[0]]->setMatrix($aParametro[2]);
				} else if ( $aParametro[2] != '' ) 
				{
					$this->aFields[$aParametro[0]]		= new InputList( $aParametro[1], $aParametro[0], $aVariables[$aParametro[0]] );
					if ( substr($aParametro[2], 0, 6) != 'SELECT' )
					{
						foreach( explode ( ',', $aParametro[2] ) as $cItem ) 
						{
							list( $codigo, $descripcion )  = explode ( ':', $cItem  );
							$this->aFields[$aParametro[0]]->addOption($codigo, $descripcion);
						}
					} else {
						$this->aFields[$aParametro[0]]->setMatrix($this->oDatabase->getMatrix($aParametro[2]) );
					}
				} else
					$this->aFields[$aParametro[0]]		= new InputText( $aParametro[1], $aParametro[0], $aVariables[$aParametro[0]] );
			}
			$this->aFields['cListaParam']->setValue( $cListaParam );
			$this->aFields['cParametros']->setHidden();
		}
	}
	function Menu_componente_frm( &$oModule )
		{
			$this->Frm( $oModule );
			//Crea los Objetos de los campos de edicion
			$this->aFields['ncMenu']		= new InputList( "Menu" , "ncMenu" );
			$this->aFields['ncOrden']		= new Input( '', "ncOrden", '', false, true );
			$this->aFields['ncMenuClave']	= new Input( '', "ncMenuClave", '', false, true );
			$this->aFields['ncComponente']	= new InputLookUp( "Componente" , "ncComponente" );
			$this->aFields['cListaParam']		= new Input( '', 'cListaParam', '' , false, true);
			$this->aFields['cParametros']		= new InputText( "Parametros","cParametros" );
			$this->aFields['nOrden']		= new InputNumber( "Orden","nOrden" );	
			$this->aFields['nPanel']			= new InputList( "Panel","nPanel", getParam('nPanel') );	
		}
	function initializeForm()
		{
			// Si viene el Ubicacion hace el retrieve
				$this->armarParametros();
				if ( $this->isRetrievable() && $this->aFields['ncMenu']->getValue() && $this->aFields['ncOrden']->getValue() )
				{
					$this->setValue( $this->aFields['ncMenu']->getValue(), $this->aFields['ncOrden']->getValue() );
				}
			// Configura el Titulo
				$this->setLabel( "Menu -  Componente" );	
			return true;
		}
	function initializeField( $cField , &$oField )
		{			
			switch ( $cField )
			{
				case 'ncMenu':
					$oField->setMatrix(armarMenuArray($this->oDatabase));
					$oField->setLanguage('es');
					$oField->setMandatory($this->isMandatory());
				break;
				case 'ncComponente':
					if ( $oField->getValue() )
					{
						$cSql = "SELECT cdComponente FROM gtComponente WHERE ncComponente = " . $oField->getValue();
						$oField->setDescription( $this->oModule->oDatabase->getData( $cSql ));
					}
					$oField->addActionArray( 2, $this->oModule->getActionArray( BUSCAR_COMPONENTE ) );
					$oField->addActionArray( 2, $this->oModule->getActionArray( AGREGAR_COMPONENTE ));
					$oField->addActionArray( 3, $this->oModule->getActionArray( MODIFICAR_COMPONENTE ));
					$oField->setFormName($this->getFormName());
					$oField->setEditable (  '?' . PARAM_REFRESH . '=class&amp;' . PARAM_MODULE . '=' . $this->oModule->cModule . '&amp;' . PARAM_ACTION . '=' . BUSCAR_COMPONENTE . '&amp;' . PARAM_CLASS . '=componente_lst&amp;' . PARAM_METHOD . '=getData' );
				
					$oField->setMandatory($this->isMandatory());
					$oField->setOnChangeAutoSubmit($this);
				break;
				case 'nPanel':
					$nModo = $this->oDatabase->getData($cSql = "SELECT nModo FROM gtMenu WHERE ncMenu= " . $this->aFields[ncMenu]->getValue() );
					if  ( ( $nModo == 1 || $nModo != 3 ) )
						$oField->addOption( 1, 'Izquierdo' );
					$oField->addOption( 2, 'Centro' );
					if  ( ( $nModo == 2  || $nModo == 3 ) )
						$oField->addOption( 3, 'Derecho' );
				break;
			}
 		}
	}
?>